// Tutorial01.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <string>
#include <iostream>
#include <HpsFramework/Protocol.hpp>
#include "ProtocolTests.h"

using namespace std;
using namespace HpsFramework::Network::Protocol;

bool onPacket1 ( void* context, ProtocolBuffer* buffer )
{
	cout << "Processing packet 1 with length of " << buffer->getSize() << " bytes" << endl;
	return true;
}

bool onPacket2 ( void* context, ProtocolBuffer* buffer )
{
	cout << "Processing packet 2 with length of " << buffer->getSize() << " bytes" << endl;
	return true;
}

int _tmain(int argc, _TCHAR* argv[])
{
	
	// if DETECT_LEAKS is defined, it'll start Visual Leak Detector
	StartLeakDetection();

	byte buffer[] = 
	{ 
		// PACKET 1
		0x00, 0x90, 
		0x00, 0x00, 0x05, 
		0x12, 0x34, 
		0x00, 0x00, 0x00, 0x00, 0x00, 
		// PACKET 2
		0x00, 0x90, 
		0x00, 0x00, 0x08, 
		0x43, 0x21, 
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
	};

	ProtocolHandler handler;
	handler.registerHandler(0x1234, &onPacket1);
	handler.registerHandler(0x4321, &onPacket2);

	size processed = handler.processBuffer ( NULL, buffer, sizeof(buffer) );

	cout << processed << " bytes processed in handler..." << endl;

	system("PAUSE");

	return 0;

}
